package ModelLayer;
import java.util.ArrayList;

/**
 * Write a description of class OrdreLibrary here.
 * 
 * @author Team Black
 * @version (a version number or a date)
 */
public class OrdreLibrary
{
    // instance variables - replace the example below with your own
    private ArrayList<Ordre> orders;
    private ArrayList<Employee> employees;
    private ArrayList<Customer> customers;
    private static OrdreLibrary Instance;
    
    private OrdreLibrary()
    {
        orders = new ArrayList<Ordre>();
        employees = new ArrayList<Employee>();
        customers = new ArrayList<Customer>();
    }
    
    public static OrdreLibrary getInstance()
    {
        if(Instance == null)
           {
               Instance = new OrdreLibrary();
           }
       return Instance;
    }
    
    public void addOrdre(Ordre _ordre)
    {
        orders.add(_ordre);
    }
    public void removeOrdre(Ordre _ordre)
    {
        orders.remove(_ordre);
    }
    public Ordre searchOrdreById(int _orderId)
    {
        boolean found = false;
        int index = 0;
        Ordre o = null;
        while(!found && index < orders.size())
        {
            Ordre ordre = orders.get(index);
            if(ordre.getOrderId() == _orderId)
            {
                found = true;
                o = ordre;
            }
            else
            {
                index++;
            }
        }
        return o;
    }
    public Ordre getOrdreByCustomer(String _name)
    {
        boolean found = false;
        int index = 0;
        Ordre retOrdre = null;
        
        while(index < orders.size() && !found)
        {
            Ordre currOrdre = orders.get(index);
            if(currOrdre.getCustomer().getName().equalsIgnoreCase(_name))
            {
                retOrdre = currOrdre;
            }
            else
            {
                index++;
            }
        }
        return retOrdre;
    }
    public Ordre getOrdreByEmployee(String _name)
    {
        boolean found = false;
        int index = 0;
        Ordre retOrdre = null;
        
        while(index < orders.size() && !found)
        {
            Ordre currOrdre = orders.get(index);
            if(currOrdre.getEmployee().getName().equalsIgnoreCase(_name))
            {
                retOrdre = currOrdre;
            }
            else
            {
                index++;
            }
        }
        return retOrdre;
    }
}
